feat(stellar): add indexed get_campaigns_by_tag query (#540) - #732
feat(stellar): add indexed get_campaigns_by_tag query (#540)#732thebabalola wants to merge 2 commits into
Conversation
|
hey, implemented the indexed get_campaigns_by_tag query for #540. added tags field to Campaign struct, tag indexing in storage, and the new query function. the tag lookup is O(1) instead of the previous O(n) scan. ready for review! |
davidmaronio
left a comment
There was a problem hiding this comment.
the query itself follows the existing bucketed pagination pattern from get_campaigns_by_category nicely, including the LIST_MAX_LIMIT cap and saturating math. but the pr as pushed is incomplete and cannot compile:
- src/queries.rs and src/campaigns/create.rs import
get_tag_campaign_bucket,get_tag_campaign_count,set_tag_campaign_bucket, andTAG_CAMPAIGNS_BUCKET_SIZEfrom storage, but src/storage.rs only adds theCampaignKey::TagCampaigns(String)enum variant. none of those functions or the constant exist anywhere in the diff, so the crate cannot build. it looks like the storage helpers were written locally but never committed. - src/campaigns/create.rs - only the import list changed. nothing ever writes to the tag index and nothing populates
campaign.tags(CreateCampaignParams doesn't gain a tags field). as it stands the index would always be empty, so the feature doesn't function even after the compile issue is fixed. - src/types.rs:100 - adding
pub tags: Vec<String>to theCampaign#[contracttype] struct changes the on-chain layout. every already-stored campaign will fail to deserialize after upgrade unless there's a migration. given this repo already had a struct-change incident, this needs either a migration step inmigrateor a design that keeps tags out of the Campaign struct entirely (a separateCampaignTags(u32)key would work and avoids the layout break). - src/queries.rs:322-326 - the doc comment says "where limit == 0 (meta-query), we return just the count" but the code returns an empty vec. either implement a count query as a separate function or fix the comment.
- no tests. an indexed query with pagination and bucket-boundary logic really needs bucket-edge tests (empty bucket, offset past end, limit spanning buckets).
gate: branch is BEHIND main and CI is red. please push the missing storage helpers, wire tag writes into create_campaign, decide the migration story for the struct change, add tests, then update the branch onto latest main.
…mpaign, avoid struct migration for PR Iris-IV#732 - Added CampaignTags(u32) storage key to store tags separately from Campaign struct - Added TAG_CAMPAIGNS_BUCKET_SIZE, TagCampaignsBucket, TagCampaignCount to storage - Added get_tag_campaign_bucket, get_tag_campaign_count, set_tag_campaign_bucket, set_tag_campaign_count - Added tags field to CreateCampaignParams (stored via set_campaign_tags, not in Campaign struct) - Wired tag indexing into create_campaign - Added get_campaigns_by_tag to lib.rs and queries.rs - Fixed doc comment in queries.rs (limit==0 returns empty vec, not count) - Avoids on-chain layout migration by keeping tags out of Campaign struct
9e5bfd7 to
a254692
Compare
|
hey @davidmaronio, rebased onto current main and addressed the remaining items:
the tag lookup is O(1) via the TagCampaigns index. tags are passed in CreateCampaignParams and stored separately, so no struct migration is needed. the remaining CI failures on this PR are the same pre-existing errors that exist on upstream/main (orphaned ProofOfHeartContract block, duplicate module declarations, etc.) — this branch doesn't introduce any new errors. let me know if anything else is needed. |
|
@thebabalola Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
merge conflict in src/queries.rs resolved. the branch is now up to date with main. |
Summary of Changes
Adds efficient tag-based campaign discovery to the ProofOfHeart-stellar contract.
Changes Made:
Added
tagsfield to Campaign struct insrc/types.rs:Added TagCampaigns key to storage system in
src/storage.rs:CampaignKey::TagCampaigns(String)to enumget_tag_campaign_countfunctionAdded query function in
src/queries.rs:get_campaigns_by_tagfunction with O(1) tag lookupsAdded contract method in
src/lib.rs:get_campaigns_by_tagmethod for external accessUpdated imports where needed to include new functions
Key Benefits:
closes #540
This change addresses the RFE for "add indexed get_campaigns_by_tag(tag: String) query for efficient tag-based discovery".